
import { ref, computed } from "vue";
import { defineStore } from "pinia";
import {Point} from '@/zondyTools/mapgis-api/Point'
import { number } from "echarts";

export const usePopupStore = defineStore(
  "popup",
  () => {
   const isPopupShow=ref(false)//是否显示弹窗
   const popupPosition=ref([114.30,30.50])//弹窗位置
   const popupContent=ref({})//弹窗内容
   const displayVideo=ref(false)//是否显示视频
   const status=ref({
      isShow:false,
      message:0,
      fid:0,
   })//事件处理状态、点击的事件id

   /* 文字弹窗显示 */
   const showPopup=function({content={},position=[114.30,30.50]}){
     isPopupShow.value=true
     displayVideo.value=false
     popupContent.value=content
     popupPosition.value=position

   }
   
   /* 关闭弹窗 */
   const hidePopup=function(){
     isPopupShow.value=false
     displayVideo.value=false
     status.value.isShow=false
   }

   /* 视频弹窗显示 */
   const showVideo=function(position){
     popupPosition.value=position
     displayVideo.value=true
     isPopupShow.value=true
   }

   /* 事件状态和id的获取与显示 */
   const showStatus=function({message=0,fid=0}){
     status.value.message=message
     status.value.fid=fid
     status.value.isShow=true
   }

   /* 关闭事件状态 */
   const hideStatus=function(){
     status.value.isShow=false
   }

   /* 设置事件状态，更新服务器数据 */
   const setStatus=function(data){
    const arr=[6,4,90]
    const color=arr[data]
     status.value.message=data
     /* 状态切换后，修改服务器数据 */
    const service={
      name: "guanggu",
      layerId: 2,
    }
    const position=popupPosition.value
    const fid=status.value.fid
    const docLayer = new Zondy.Map.Doc("", "guanggu", {});
    //attr =[{name: 'name', value: '武汉', type: 'String'},{name:'id',type:'number',value:123}]
    const attr=[
      {name: '事件编号', value: popupContent.value["事件编号"], type: 'String'},
      {name:'事件类型',type:'Number',value:popupContent.value["事件类型"]},
      {name:"事件等级",type:'Number',value:popupContent.value["事件等级"]},
      {name:"发生时间",type:'String',value:popupContent.value["发生时间"]},
      {name:"发生地点",type:'String',value:popupContent.value["发生地点"]},
      {name:"车牌号",type:'String',value:popupContent.value["车牌号"]},
      {name:"驾驶员",type:'String',value:popupContent.value["驾驶员"]},
      {name:'处理状态',type:'Number',value:data},
      {name:"mpLayer",type:'Number',value:0},
    ]

    Point.update({position, attr, docLayer, service, fid,color})
   }
   
   return {
     isPopupShow,
     popupPosition,
     displayVideo,
     status,
     popupContent,
     showPopup,
     hidePopup,
     showVideo,
     showStatus,
     setStatus,
     hideStatus
     }
  },

);